﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SlotJoint.CUiSlotJointWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;
using UiInternalControls;
using UiInternalControls.WPF;
using UiInternalControls.WPFControls;


namespace DnProcessSimulateCommands.SlotJoint;

public class CUiSlotJointWindow : 
  TxWindow,
  ITxManagedDialogSlotJointDialog,
  ITxManagedDialog,
  ITxManagedDialogEvents,
  IComponentConnector
{
  private CApSlotJointApp _viewModel;
  private CApPointManipulator _pin1Manipulator;
  private CApPointManipulator _pin2Manipulator;
  private CApPointManipulator _offsetPointManipulator;
  private CApPlaneManipulator _planeManipulator;
  private TxColor _pin1Color;
  private TxColor _pin2Color;
  private TxColor _offsetPointColor;
  private CApSlotJointCurveValidator _curveValidator;
  private Storyboard _storyboard;
  private bool _isCurve2CtrlInitialized;
  private bool _moveFocusToNextControl = true;
  private bool _updateMinMaxWindowHeight;
  private TxPickLevelEx _originalPickLevel;
  internal ComboBox slotJointType;
  internal Expander diagramExpander;
  internal Canvas canvasTwoSlots;
  internal Canvas canvasGun;
  internal Path canvasUpperLink;
  internal Path canvasLowerLinkSingleSlot;
  internal Path canvasLowerLinkDualSlot;
  internal Path canvasCurveSingleSlotTransparent;
  internal Path canvasCurveSingleSlot;
  internal Path canvasCurve2Transparent;
  internal Path canvasCurve2;
  internal Path canvasCurve1Transparent;
  internal Path canvasCurve1;
  internal Grid canvasPin2Grid;
  internal Path canvasPin2;
  internal Grid canvasPin1Grid;
  internal Path canvasPin1;
  internal Ellipse offsetPointTransparent;
  internal Ellipse offset;
  internal Canvas canvasLabels;
  internal TextBlock selectElementFromDiagram;
  internal Grid leadingCurve2Label;
  internal TextBlock leadingCurve2Diagram;
  internal Grid leadingCurve1Label;
  internal TextBlock leadingCurve1Diagram;
  internal Grid canvasPinName2;
  internal Grid canvasPinName1;
  internal Grid offsetName;
  internal TextBlock previewJog;
  internal Expander parametersExpander;
  internal TextBlock curve1Label;
  internal TxObjEditBoxControl curve1Ctrl;
  internal Tx3DVectorControl pin1Ctrl;
  internal TextBlock curve2Label;
  internal TxObjEditBoxControl curve2Ctrl;
  internal Tx3DVectorControl pin2Ctrl;
  internal CheckBox useOffsetPointCtrl;
  internal TxInfoButton offsetInformationImage;
  internal Tx3DVectorControl offsetPointCtrl;
  internal Button btnOk;
  internal Button btnClose;
  internal StatusBar statusBar;
  internal Image iMessageType;
  internal TextBlock tbMessage;
  private bool _contentLoaded;

  public CUiSlotJointWindow()
  {
    this._pin1Color = TxColor.TxColorOrange;
    this._pin2Color = TxColor.TxColorBlue;
    this._offsetPointColor = new TxColor((byte) 175, (byte) 35, (byte) 95);
    this.InitializeComponent();
    this._viewModel = new CApSlotJointApp(true);
    ((FrameworkElement) this).DataContext = (object) this._viewModel;
    this.InitSlotJointTypes();
    this.LoadValuesFromRegistry();
    this.ListenToEvents();
    this.InitCurve1Ctrl();
    this._originalPickLevel = TxGraphicViewerEx.PickLevel;
    TxGraphicViewerEx.PickLevel = (TxPickLevelEx) 2;
    this._viewModel.PropertyChanged += new PropertyChangedEventHandler(this._viewModel_PropertyChanged);
  }

  private void _viewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    if (!this._moveFocusToNextControl)
      return;
    switch (e.PropertyName)
    {
      case "LeadingCurve1Set":
        if (!this._viewModel.LeadingCurve1Set)
          break;
        this.pin1Ctrl.Focus();
        this._viewModel.Pin1Selected = true;
        break;
      case "LeadingCurve2Set":
        if (!this._viewModel.LeadingCurve2Set)
          break;
        this.pin2Ctrl.Focus();
        this._viewModel.Pin2Selected = true;
        break;
      case "Pin1Set":
        if (!this._viewModel.Pin1Set)
          break;
        if (this._viewModel.SelectedSlotJointType == 0)
        {
          this.pin2Ctrl.Focus();
          this._viewModel.Pin2Selected = true;
          break;
        }
        if (this._viewModel.SelectedSlotJointType != 1)
          break;
        this.curve2Ctrl.Focus();
        this._viewModel.LeadingCurve2Selected = true;
        break;
      case "Pin2Set":
        if (!this._viewModel.Pin2Set)
          break;
        this.pin2Ctrl.LoseFocus();
        this._viewModel.Pin2Selected = false;
        if (this._viewModel.UseOffsetPoint)
        {
          this.offsetPointCtrl.Focus();
          break;
        }
        this.btnOk.Focus();
        break;
      case "OffsetPointSet":
        if (!this._viewModel.OffsetPointSet)
          break;
        this.btnOk.Focus();
        this._viewModel.OffsetPointSelected = false;
        break;
    }
  }

  private void StoreValuesToRegistry()
  {
    TxWindowSettings.StoreWindowValue((TxWindow) this, "SlotJointType", (object) this._viewModel.SelectedSlotJointType);
  }

  private void LoadValuesFromRegistry()
  {
    object obj = (object) null;
    TxWindowSettings.RestoreWindowValue((TxWindow) this, "SlotJointType", ref obj);
    SlotJointType result;
    if (obj == null || !Enum.TryParse<SlotJointType>(obj.ToString(), out result))
      return;
    this._viewModel.SelectedSlotJointType = (int) result;
  }

  private void offsetPointCtrl_ValueChanged(object sender, EventArgs e)
  {
    this.SetOffsetPointValue(this.offsetPointCtrl.Value);
  }

  private void pin1Ctrl_ValueChanged(object sender, EventArgs e)
  {
    this.SetPin1Value(this.pin1Ctrl.Value);
  }

  private void pin2Ctrl_ValueChanged(object sender, EventArgs e)
  {
    this.SetPin2Value(this.pin2Ctrl.Value);
  }

  private void CreatePlaneManipulator()
  {
    this.DestroyPlaneManipulator();
    if (this.Manager.ModeledMechanism is ITxLocatableObject)
    {
      ITxLocatableObject modeledMechanism = this.Manager.ModeledMechanism as ITxLocatableObject;
      TxPlaneData curvesPlaneData = CApSlotJointUtils.GetCurvesPlaneData(this._viewModel.LeadingCurve1, this._viewModel.LeadingCurve2);
      if (TxPlaneData.op_Inequality(curvesPlaneData, (TxPlaneData) null))
        this._planeManipulator = new CApPlaneManipulator(this.Manager.ModeledMechanism as ITxLocatableObject, new TxTransformation(curvesPlaneData.ProjectPoint(modeledMechanism.GeometricCenter.Translation), curvesPlaneData.Normal));
    }
    TxApplication.RefreshDisplay();
  }

  private void LeadingCurve1ValueUpdated()
  {
    this.ReprojectPoints();
    if (this._viewModel.LeadingCurve1 != null && this._viewModel.ValidateLeadingCurve(true))
    {
      this._viewModel.LeadingCurve1Set = true;
      this._viewModel.ClearErrorMessage();
    }
    else
      this._viewModel.LeadingCurve1Set = false;
    this.CreatePlaneManipulator();
    this._viewModel.UpdateIsDataReadyProperty();
  }

  private void LeadingCurve2ValueUpdated()
  {
    this.ReprojectPoints();
    if (this._viewModel.LeadingCurve2 != null && this._viewModel.ValidateLeadingCurve(false))
    {
      this._viewModel.LeadingCurve2Set = true;
      this._viewModel.ClearErrorMessage();
    }
    else
      this._viewModel.LeadingCurve2Set = false;
    this.CreatePlaneManipulator();
    this._viewModel.UpdateIsDataReadyProperty();
  }

  private void ReprojectPoints()
  {
    this._moveFocusToNextControl = false;
    if (this._viewModel.Pin1Set)
      this.SetPin1Value(this.pin1Ctrl.Value, false);
    if (this._viewModel.Pin2Set)
      this.SetPin2Value(this.pin2Ctrl.Value, false);
    if (this._viewModel.OffsetPointSet)
      this.SetOffsetPointValue(this.offsetPointCtrl.Value, false);
    this._moveFocusToNextControl = true;
  }

  private void CreatePointManipulator(
    ref CApPointManipulator manipulator,
    TxVector pickedPoint,
    TxVector projectedPoint,
    TxColor color)
  {
    if (TxVector.op_Inequality(pickedPoint, (TxVector) null) || TxVector.op_Inequality(projectedPoint, (TxVector) null))
    {
      TxTransformation pickedLocationTransformation = new TxTransformation(pickedPoint, (TxTransformation.TxTransformationType) 1);
      TxTransformation projectedLocationTransformation = (TxTransformation) null;
      if (TxVector.op_Inequality(projectedPoint, (TxVector) null))
        projectedLocationTransformation = new TxTransformation(projectedPoint, (TxTransformation.TxTransformationType) 1);
      if (manipulator == null)
        manipulator = new CApPointManipulator(pickedLocationTransformation, projectedLocationTransformation, color);
      else
        manipulator.ChangeManipulatorLocation(pickedLocationTransformation, projectedLocationTransformation);
    }
    else
      this.DestroyPointManipulator(ref manipulator);
  }

  private void SetPin1Value(TxVector pickedPoint, bool isChangedFromUi = true)
  {
    TxVector txVector = this._viewModel.ProjectPointOnCurvePlane(pickedPoint);
    if (TxVector.op_Inequality(pickedPoint, (TxVector) null) && (TxVector.op_Equality(txVector, (TxVector) null) || this._viewModel.ValidatePinPosition(txVector, true)))
    {
      this._viewModel.Pin1Set = true;
      this.pin1Ctrl.Value = pickedPoint;
      if (isChangedFromUi)
        this._viewModel.ClearErrorMessage();
    }
    else
      this._viewModel.Pin1Set = false;
    this._viewModel.UpdateIsDataReadyProperty();
    this.CreatePointManipulator(ref this._pin1Manipulator, pickedPoint, txVector, this._pin1Color);
    TxApplication.RefreshDisplay();
  }

  private void SetPin2Value(TxVector pickedPoint, bool isChangedFromUi = true)
  {
    TxVector txVector = this._viewModel.ProjectPointOnCurvePlane(pickedPoint);
    if (TxVector.op_Inequality(pickedPoint, (TxVector) null) && (TxVector.op_Equality(txVector, (TxVector) null) || this._viewModel.ValidatePinPosition(txVector, false)))
    {
      this._viewModel.Pin2Set = true;
      this.pin2Ctrl.Value = pickedPoint;
      if (isChangedFromUi)
        this._viewModel.ClearErrorMessage();
    }
    else
      this._viewModel.Pin2Set = false;
    this._viewModel.UpdateIsDataReadyProperty();
    this.CreatePointManipulator(ref this._pin2Manipulator, pickedPoint, txVector, this._pin2Color);
    TxApplication.RefreshDisplay();
  }

  private void SetOffsetPointValue(TxVector pickedPoint, bool isChangedFromUi = true)
  {
    TxVector txVector = this._viewModel.ProjectPointOnCurvePlane(pickedPoint);
    if (TxVector.op_Inequality(pickedPoint, (TxVector) null) && (TxVector.op_Equality(txVector, (TxVector) null) || this._viewModel.ValidateOffsetPoint(txVector)))
    {
      this._viewModel.OffsetPointSet = true;
      this.offsetPointCtrl.Value = pickedPoint;
      if (isChangedFromUi)
        this._viewModel.ClearErrorMessage();
    }
    else
      this._viewModel.OffsetPointSet = false;
    this._viewModel.UpdateIsDataReadyProperty();
    this.CreatePointManipulator(ref this._offsetPointManipulator, pickedPoint, txVector, this._offsetPointColor);
    TxApplication.RefreshDisplay();
  }

  private void InitCurve1Ctrl()
  {
    // ISSUE: unable to decompile the method.
  }

  private void InitCurve2Ctrl()
  {
    // ISSUE: unable to decompile the method.
  }

  private void ListenToEvents()
  {
    this.pin1Ctrl.ValueXChanged += new EventHandler(this.pin1Ctrl_ValueChanged);
    this.pin1Ctrl.ValueYChanged += new EventHandler(this.pin1Ctrl_ValueChanged);
    this.pin1Ctrl.ValueZChanged += new EventHandler(this.pin1Ctrl_ValueChanged);
    this.pin2Ctrl.ValueXChanged += new EventHandler(this.pin2Ctrl_ValueChanged);
    this.pin2Ctrl.ValueYChanged += new EventHandler(this.pin2Ctrl_ValueChanged);
    this.pin2Ctrl.ValueZChanged += new EventHandler(this.pin2Ctrl_ValueChanged);
    this.offsetPointCtrl.ValueXChanged += new EventHandler(this.offsetPointCtrl_ValueChanged);
    this.offsetPointCtrl.ValueYChanged += new EventHandler(this.offsetPointCtrl_ValueChanged);
    this.offsetPointCtrl.ValueZChanged += new EventHandler(this.offsetPointCtrl_ValueChanged);
  }

  private void UpdateSlotTypeLayout()
  {
    if (this._viewModel.SelectedSlotJointType == 0)
      this.SetSingleSlotLayout();
    else
      this.SetTwoSlotsLayout();
  }

  private void InitSlotJointTypes()
  {
    this.slotJointType.ItemsSource = (IEnumerable) new ArrayList()
    {
      (object) DnProcessSimulateCommands.SlotJoint.Resources.StringTable.OneSlot,
      (object) DnProcessSimulateCommands.SlotJoint.Resources.StringTable.TwoSlots
    };
    this._viewModel.SelectedSlotJointType = 0;
  }

  private void SetSingleSlotLayout()
  {
    this.canvasLowerLinkSingleSlot.Visibility = Visibility.Visible;
    this.canvasLowerLinkDualSlot.Visibility = Visibility.Hidden;
    this.canvasCurve1Transparent.Visibility = Visibility.Hidden;
    this.canvasCurve2Transparent.Visibility = Visibility.Hidden;
    this.canvasCurve1.Visibility = Visibility.Hidden;
    this.canvasCurve2.Visibility = Visibility.Hidden;
    this.canvasCurveSingleSlotTransparent.Visibility = Visibility.Visible;
    this.canvasCurveSingleSlot.Visibility = Visibility.Visible;
    this.leadingCurve2Label.Visibility = Visibility.Hidden;
    this.leadingCurve2Diagram.Visibility = Visibility.Hidden;
    this.leadingCurve1Diagram.Text = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.LeadingCurveDiagram;
    this.InitStoryboard("gunOpenSingleSlot");
    this.curve2Label.Visibility = Visibility.Collapsed;
    ((UIElement) this.curve2Ctrl).Visibility = Visibility.Collapsed;
    this.curve1Label.Text = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.LeadingCurveLabel;
    this.curve1Ctrl.Focus();
  }

  private void SetTwoSlotsLayout()
  {
    this.canvasLowerLinkSingleSlot.Visibility = Visibility.Hidden;
    this.canvasLowerLinkDualSlot.Visibility = Visibility.Visible;
    this.canvasCurve1Transparent.Visibility = Visibility.Visible;
    this.canvasCurve2Transparent.Visibility = Visibility.Visible;
    this.canvasCurve1.Visibility = Visibility.Visible;
    this.canvasCurve2.Visibility = Visibility.Visible;
    this.canvasCurveSingleSlotTransparent.Visibility = Visibility.Hidden;
    this.canvasCurveSingleSlot.Visibility = Visibility.Hidden;
    this.leadingCurve2Label.Visibility = Visibility.Visible;
    this.leadingCurve2Diagram.Visibility = Visibility.Visible;
    this.leadingCurve1Diagram.Text = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.LeadingCurve1Diagram;
    this.InitStoryboard("gunOpenDualSlot");
    if (!this._isCurve2CtrlInitialized)
    {
      this.InitCurve2Ctrl();
      this._isCurve2CtrlInitialized = true;
    }
    this.curve2Label.Visibility = Visibility.Visible;
    ((UIElement) this.curve2Ctrl).Visibility = Visibility.Visible;
    this.curve1Label.Text = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.LeadingCurve1Label;
    this.curve2Label.Text = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.LeadingCurve2Label;
    this.curve1Ctrl.Focus();
  }

  private void btnOk_Click(object sender, RoutedEventArgs e)
  {
    bool flag = true;
    if (this.Manager != null)
      flag = this._viewModel.CreateSlotJoint(this.Manager);
    if (!flag)
      return;
    ((Window) this).Close();
  }

  private void curve1Ctrl_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
    {
      this._viewModel.Message = this._curveValidator.DetailedErrorMessage;
      this._viewModel.MessageType = this._curveValidator.ErrorType;
    }
    this.LeadingCurve1ValueUpdated();
  }

  private void curve2Ctrl_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
    {
      this._viewModel.Message = this._curveValidator.DetailedErrorMessage;
      this._viewModel.MessageType = this._curveValidator.ErrorType;
    }
    this.LeadingCurve2ValueUpdated();
  }

  private void curve1Ctrl_TypeValid(object sender, EventArgs e) => this.LeadingCurve1ValueUpdated();

  private void curve1Ctrl_TypeInvalid(object sender, EventArgs e)
  {
    this._viewModel.Message = this._curveValidator.DetailedErrorMessage;
    this._viewModel.MessageType = this._curveValidator.ErrorType;
    this.LeadingCurve1ValueUpdated();
  }

  private void curve2Ctrl_TypeValid(object sender, EventArgs e) => this.LeadingCurve2ValueUpdated();

  private void curve2Ctrl_TypeInvalid(object sender, EventArgs e)
  {
    this._viewModel.Message = this._curveValidator.DetailedErrorMessage;
    this._viewModel.MessageType = this._curveValidator.ErrorType;
    this.LeadingCurve2ValueUpdated();
  }

  private void pin1Ctrl_Picked(object sender, Tx3DVectorCtrl_PickedEventArgs args)
  {
    if (args == null)
      return;
    TxVector pickedPoint = (TxVector) null;
    if (TxTransformation.op_Inequality(args.Location, (TxTransformation) null) && TxVector.op_Inequality(args.Location.Translation, (TxVector) null))
      pickedPoint = args.Location.Translation;
    else if (args.Obj is TxFrame)
      pickedPoint = (args.Obj as TxFrame).AbsoluteLocation.Translation;
    this.SetPin1Value(pickedPoint);
  }

  private void pin2Ctrl_Picked(object sender, Tx3DVectorCtrl_PickedEventArgs args)
  {
    if (args == null)
      return;
    TxVector pickedPoint = (TxVector) null;
    if (TxTransformation.op_Inequality(args.Location, (TxTransformation) null) && TxVector.op_Inequality(args.Location.Translation, (TxVector) null))
      pickedPoint = args.Location.Translation;
    else if (args.Obj is TxFrame)
      pickedPoint = (args.Obj as TxFrame).AbsoluteLocation.Translation;
    this.SetPin2Value(pickedPoint);
  }

  private void offsetPointCtrl_Picked(object sender, Tx3DVectorCtrl_PickedEventArgs args)
  {
    if (args == null)
      return;
    TxVector translation;
    if (TxTransformation.op_Inequality(args.Location, (TxTransformation) null) && TxVector.op_Inequality(args.Location.Translation, (TxVector) null))
    {
      translation = args.Location.Translation;
    }
    else
    {
      if (!(args.Obj is TxFrame))
        return;
      translation = (args.Obj as TxFrame).AbsoluteLocation.Translation;
    }
    this.SetOffsetPointValue(translation);
  }

  private void SlotJointType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    this._viewModel.ClearErrorMessage();
    if (((FrameworkElement) this).IsLoaded)
      this.ResetData();
    this.UpdateSlotTypeLayout();
    this._viewModel.UpdateIsDataReadyProperty();
  }

  private void ResetData()
  {
    this._viewModel.LeadingCurve1 = (ITx1DimensionalGeometry) null;
    this._viewModel.LeadingCurve2 = (ITx1DimensionalGeometry) null;
    this._viewModel.LeadingCurve1Set = false;
    this._viewModel.LeadingCurve2Set = false;
    this._viewModel.Pin1Value = new TxVector();
    this._viewModel.Pin2Value = new TxVector();
    this._viewModel.OffsetPointValue = new TxVector();
    this._viewModel.Pin1Set = false;
    this._viewModel.Pin2Set = false;
    this._viewModel.OffsetPointSet = false;
    this._viewModel.ClearErrorMessage();
    this.DestroyPointManipulator(ref this._pin1Manipulator);
    this.DestroyPointManipulator(ref this._pin2Manipulator);
    this.DestroyPointManipulator(ref this._offsetPointManipulator);
    this.DestroyPlaneManipulator();
    TxApplication.RefreshDisplay();
  }

  private void btnClose_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  IntPtr ITxManagedDialog.Handle => new WindowInteropHelper((Window) this).Handle;

  void ITxManagedDialog.Close() => ((Window) this).Close();

  void ITxManagedDialog.Show() => ((Window) this).Show();

  void ITxManagedDialog.Show(IntPtr owner) => this.Show(owner);

  bool ITxManagedDialog.ShowDialog()
  {
    bool? nullable = this.ShowDialog(true);
    return nullable.HasValue && nullable.Value;
  }

  private void TxWindow_Closed(object sender, EventArgs e)
  {
    this.StoreValuesToRegistry();
    this.ResetData();
    TxGraphicViewerEx.PickLevel = this._originalPickLevel;
  }

  event EventHandler ITxManagedDialogEvents.Closed
  {
    add => ((Window) this).Closed += value;
    remove => ((Window) this).Closed -= value;
  }

  public ITxManagedDialogSlotJoint Manager { get; set; }

  private void curve1Ctrl_GotFocus(object sender, RoutedEventArgs e)
  {
    this._viewModel.LeadingCurve1Selected = true;
  }

  private void curve2Ctrl_GotFocus(object sender, RoutedEventArgs e)
  {
    this._viewModel.LeadingCurve2Selected = true;
  }

  private void pin1Ctrl_GotFocus(object sender, RoutedEventArgs e)
  {
    this._viewModel.Pin1Selected = true;
    if (TxGraphicViewerEx.PickLevel == 2)
      return;
    TxGraphicViewerEx.PickLevel = (TxPickLevelEx) 2;
  }

  private void pin2Ctrl_GotFocus(object sender, RoutedEventArgs e)
  {
    this._viewModel.Pin2Selected = true;
    if (TxGraphicViewerEx.PickLevel == 2)
      return;
    TxGraphicViewerEx.PickLevel = (TxPickLevelEx) 2;
  }

  private void offsetPointCtrl_GotFocus(object sender, RoutedEventArgs e)
  {
    this._viewModel.OffsetPointSelected = true;
    if (TxGraphicViewerEx.PickLevel == 2)
      return;
    TxGraphicViewerEx.PickLevel = (TxPickLevelEx) 2;
  }

  private void curve1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    this._viewModel.LeadingCurve1Selected = true;
  }

  private void curve2_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    this._viewModel.LeadingCurve2Selected = true;
  }

  private void pin1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    this._viewModel.Pin1Selected = true;
  }

  private void pin2_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    this._viewModel.Pin2Selected = true;
  }

  private void InitStoryboard(string storyBoardName)
  {
    this._storyboard = this.canvasGun.FindResource((object) storyBoardName) as Storyboard;
    this._storyboard.SpeedRatio = 3.0;
    this._storyboard.AutoReverse = true;
    this._storyboard.Begin((FrameworkElement) this.canvasUpperLink, true);
    this._storyboard.Pause((FrameworkElement) this.canvasUpperLink);
  }

  private void previewJog_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    if (!this._storyboard.GetIsPaused((FrameworkElement) this.canvasUpperLink))
      return;
    this.slotJointType.IsEnabled = false;
    this._storyboard.Completed += new EventHandler(this.sb_Completed_Backward);
    this._storyboard.Begin((FrameworkElement) this.canvasUpperLink, true);
    this.leadingCurve1Label.Visibility = this.canvasPinName1.Visibility = this.canvasPinName2.Visibility = this.offsetName.Visibility = this.selectElementFromDiagram.Visibility = Visibility.Hidden;
    if (this._viewModel.SelectedSlotJointType != 1)
      return;
    this.leadingCurve2Label.Visibility = Visibility.Hidden;
  }

  private void sb_Completed_Backward(object sender, EventArgs e)
  {
    this._storyboard.Completed -= new EventHandler(this.sb_Completed_Backward);
    this._storyboard.Remove();
    this._storyboard.Begin((FrameworkElement) this.canvasUpperLink, true);
    this._storyboard.Pause((FrameworkElement) this.canvasUpperLink);
    this.leadingCurve1Label.Visibility = this.canvasPinName1.Visibility = this.canvasPinName2.Visibility = this.offsetName.Visibility = this.selectElementFromDiagram.Visibility = Visibility.Visible;
    if (this._viewModel.SelectedSlotJointType == 1)
      this.leadingCurve2Label.Visibility = Visibility.Visible;
    this.slotJointType.IsEnabled = true;
  }

  private bool DestroyPointManipulator(ref CApPointManipulator manipulator)
  {
    if (manipulator == null)
      return false;
    manipulator.DestroyManipulator();
    manipulator = (CApPointManipulator) null;
    return true;
  }

  private void DestroyPlaneManipulator()
  {
    if (this._planeManipulator == null)
      return;
    this._planeManipulator.DestroyManipulator();
    this._planeManipulator = (CApPlaneManipulator) null;
  }

  private void useOffsetPointCtrl_Checked(object sender, RoutedEventArgs e)
  {
    if (this._viewModel.OffsetPointSet)
      this.SetOffsetPointValue(this._viewModel.OffsetPointValue);
    ((UIElement) this.offsetPointCtrl).IsEnabled = true;
  }

  private void useOffsetPointCtrl_Unchecked(object sender, RoutedEventArgs e)
  {
    if (this.DestroyPointManipulator(ref this._offsetPointManipulator))
    {
      this._viewModel.ClearErrorMessage();
      TxApplication.RefreshDisplay();
    }
    ((UIElement) this.offsetPointCtrl).IsEnabled = false;
    this._viewModel.UpdateIsDataReadyProperty();
  }

  private void offset_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
    this._viewModel.OffsetPointSelected = true;
  }

  private void diagramExpander_ExpandedCollapsed(object sender, RoutedEventArgs e)
  {
    this._updateMinMaxWindowHeight = true;
    if (this._viewModel == null)
      return;
    this._viewModel.ClearSelection();
  }

  private void HideParametersControls(bool hide = true) => this._curveValidator.ShowTooltip = !hide;

  private void parametersExpander_ExpandedCollapsed(object sender, RoutedEventArgs e)
  {
    if (!((FrameworkElement) this).IsLoaded)
      return;
    this._updateMinMaxWindowHeight = true;
    this.HideParametersControls(!this.parametersExpander.IsExpanded);
    if (this._viewModel == null)
      return;
    this._viewModel.ClearSelection();
  }

  private void tbMessage_SizeChanged(object sender, SizeChangedEventArgs e)
  {
    this._updateMinMaxWindowHeight = true;
  }

  private void CUiSlotJointWindow_LayoutUpdated(object sender, EventArgs e)
  {
    if (!this._updateMinMaxWindowHeight)
      return;
    TxWindowBehavior.SetIsVerticallyResizable((DependencyObject) this, false);
    this.UpdateMinMaxHeight();
    this._updateMinMaxWindowHeight = false;
  }

  private void UpdateMinMaxHeight()
  {
    ((FrameworkElement) this).MaxHeight = double.PositiveInfinity;
    ((FrameworkElement) this).MinHeight = 0.0;
    ((Window) this).SizeToContent = SizeToContent.Height;
    ((UIElement) this).UpdateLayout();
    ((FrameworkElement) this).MaxHeight = ((FrameworkElement) this).MinHeight = ((FrameworkElement) this).ActualHeight;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/slotjoint/cuislotjointwindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  internal Delegate _CreateDelegate(Type delegateType, string handler)
  {
    return Delegate.CreateDelegate(delegateType, (object) this, handler);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((Window) target).Closed += new EventHandler(this.TxWindow_Closed);
        ((UIElement) target).LayoutUpdated += new EventHandler(this.CUiSlotJointWindow_LayoutUpdated);
        break;
      case 2:
        this.slotJointType = (ComboBox) target;
        this.slotJointType.SelectionChanged += new SelectionChangedEventHandler(this.SlotJointType_SelectionChanged);
        break;
      case 3:
        this.diagramExpander = (Expander) target;
        this.diagramExpander.Expanded += new RoutedEventHandler(this.diagramExpander_ExpandedCollapsed);
        this.diagramExpander.Collapsed += new RoutedEventHandler(this.diagramExpander_ExpandedCollapsed);
        break;
      case 4:
        this.canvasTwoSlots = (Canvas) target;
        break;
      case 5:
        this.canvasGun = (Canvas) target;
        break;
      case 6:
        this.canvasUpperLink = (Path) target;
        break;
      case 7:
        this.canvasLowerLinkSingleSlot = (Path) target;
        break;
      case 8:
        this.canvasLowerLinkDualSlot = (Path) target;
        break;
      case 9:
        this.canvasCurveSingleSlotTransparent = (Path) target;
        this.canvasCurveSingleSlotTransparent.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.curve1_PreviewMouseLeftButtonDown);
        break;
      case 10:
        this.canvasCurveSingleSlot = (Path) target;
        break;
      case 11:
        this.canvasCurve2Transparent = (Path) target;
        this.canvasCurve2Transparent.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.curve2_PreviewMouseLeftButtonDown);
        break;
      case 12:
        this.canvasCurve2 = (Path) target;
        break;
      case 13:
        this.canvasCurve1Transparent = (Path) target;
        this.canvasCurve1Transparent.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.curve1_PreviewMouseLeftButtonDown);
        break;
      case 14:
        this.canvasCurve1 = (Path) target;
        break;
      case 15:
        this.canvasPin2Grid = (Grid) target;
        break;
      case 16 /*0x10*/:
        this.canvasPin2 = (Path) target;
        this.canvasPin2.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.pin2_PreviewMouseLeftButtonDown);
        break;
      case 17:
        this.canvasPin1Grid = (Grid) target;
        break;
      case 18:
        this.canvasPin1 = (Path) target;
        this.canvasPin1.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.pin1_PreviewMouseLeftButtonDown);
        break;
      case 19:
        this.offsetPointTransparent = (Ellipse) target;
        this.offsetPointTransparent.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.offset_PreviewMouseLeftButtonDown);
        break;
      case 20:
        this.offset = (Ellipse) target;
        break;
      case 21:
        this.canvasLabels = (Canvas) target;
        break;
      case 22:
        this.selectElementFromDiagram = (TextBlock) target;
        break;
      case 23:
        this.leadingCurve2Label = (Grid) target;
        break;
      case 24:
        this.leadingCurve2Diagram = (TextBlock) target;
        this.leadingCurve2Diagram.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.curve2_PreviewMouseLeftButtonDown);
        break;
      case 25:
        this.leadingCurve1Label = (Grid) target;
        break;
      case 26:
        this.leadingCurve1Diagram = (TextBlock) target;
        this.leadingCurve1Diagram.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.curve1_PreviewMouseLeftButtonDown);
        break;
      case 27:
        this.canvasPinName2 = (Grid) target;
        break;
      case 28:
        ((UIElement) target).PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.pin2_PreviewMouseLeftButtonDown);
        break;
      case 29:
        this.canvasPinName1 = (Grid) target;
        break;
      case 30:
        ((UIElement) target).PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.pin1_PreviewMouseLeftButtonDown);
        break;
      case 31 /*0x1F*/:
        this.offsetName = (Grid) target;
        break;
      case 32 /*0x20*/:
        ((UIElement) target).PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.offset_PreviewMouseLeftButtonDown);
        break;
      case 33:
        ((UIElement) target).PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.previewJog_PreviewMouseLeftButtonDown);
        break;
      case 34:
        this.previewJog = (TextBlock) target;
        break;
      case 35:
        this.parametersExpander = (Expander) target;
        this.parametersExpander.Expanded += new RoutedEventHandler(this.parametersExpander_ExpandedCollapsed);
        this.parametersExpander.Collapsed += new RoutedEventHandler(this.parametersExpander_ExpandedCollapsed);
        break;
      case 36:
        this.curve1Label = (TextBlock) target;
        break;
      case 37:
        this.curve1Ctrl = (TxObjEditBoxControl) target;
        this.curve1Ctrl.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.curve1Ctrl_Picked);
        ((UIElement) this.curve1Ctrl).GotFocus += new RoutedEventHandler(this.curve1Ctrl_GotFocus);
        break;
      case 38:
        this.pin1Ctrl = (Tx3DVectorControl) target;
        this.pin1Ctrl.Picked += new Tx3DVectorCtrl_PickedEventHandler(this.pin1Ctrl_Picked);
        ((UIElement) this.pin1Ctrl).GotFocus += new RoutedEventHandler(this.pin1Ctrl_GotFocus);
        break;
      case 39:
        this.curve2Label = (TextBlock) target;
        break;
      case 40:
        this.curve2Ctrl = (TxObjEditBoxControl) target;
        this.curve2Ctrl.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.curve2Ctrl_Picked);
        ((UIElement) this.curve2Ctrl).GotFocus += new RoutedEventHandler(this.curve2Ctrl_GotFocus);
        break;
      case 41:
        this.pin2Ctrl = (Tx3DVectorControl) target;
        this.pin2Ctrl.Picked += new Tx3DVectorCtrl_PickedEventHandler(this.pin2Ctrl_Picked);
        ((UIElement) this.pin2Ctrl).GotFocus += new RoutedEventHandler(this.pin2Ctrl_GotFocus);
        break;
      case 42:
        this.useOffsetPointCtrl = (CheckBox) target;
        this.useOffsetPointCtrl.Checked += new RoutedEventHandler(this.useOffsetPointCtrl_Checked);
        this.useOffsetPointCtrl.Unchecked += new RoutedEventHandler(this.useOffsetPointCtrl_Unchecked);
        break;
      case 43:
        this.offsetInformationImage = (TxInfoButton) target;
        break;
      case 44:
        this.offsetPointCtrl = (Tx3DVectorControl) target;
        this.offsetPointCtrl.Picked += new Tx3DVectorCtrl_PickedEventHandler(this.offsetPointCtrl_Picked);
        ((UIElement) this.offsetPointCtrl).GotFocus += new RoutedEventHandler(this.offsetPointCtrl_GotFocus);
        break;
      case 45:
        this.btnOk = (Button) target;
        this.btnOk.Click += new RoutedEventHandler(this.btnOk_Click);
        break;
      case 46:
        this.btnClose = (Button) target;
        this.btnClose.Click += new RoutedEventHandler(this.btnClose_Click);
        break;
      case 47:
        this.statusBar = (StatusBar) target;
        break;
      case 48 /*0x30*/:
        this.iMessageType = (Image) target;
        break;
      case 49:
        this.tbMessage = (TextBlock) target;
        this.tbMessage.SizeChanged += new SizeChangedEventHandler(this.tbMessage_SizeChanged);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
